package com.link.base.base.productplan.controller;

import com.link.base.base.productplan.model.ProdPlanHead;
import com.link.base.base.productplan.service.ProdPlanHeadService;
import com.link.base.base.productplan.service.ProdPlanService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author unknown
 * @date unknown
 * @comments 产品计划信息
 */
@Controller
@RequestMapping("/link/prodPlanHead")
public class ProdPlanHeadController extends BasicController<ProdPlanHead> {

    @Resource
    private ProdPlanHeadService prodPlanHeadService;

    @Resource
    private ProdPlanService prodPlanService;

    @Override
    public BasicService<ProdPlanHead> getBasicService() throws Exception {
        return prodPlanHeadService;
    }

    @Override
    @RequestMapping({"/deleteById"})
    @ResponseBody
    public Map<String, Object> deleteById(@JsonParam ProdPlanHead entity, HttpSession session,
                                          HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap();

        try {
            this.beforDelete(entity, request);
            this.checkData(entity, request);
            String base = "base";
            if (!this.checkExistDataCache(base, session, entity)) {
                throw new ServiceException("PUBLIC-031");
            }
            this.getBasicService().deleteById(entity);
            prodPlanService.deleteByHeadId(entity.getId());
            result.put("success", true);
        } catch (BasicServiceException var7) {
            LCLogger.withException(var7);
            result.put("success", false);
            result.put("result", var7.getMessage());
            result.put("detailMessage", var7.getDetailMessage());
        } catch (Exception var8) {
            LCLogger.withException(var8);
            result.put("success", false);
            result.put("result", var8.getMessage());
        }

        return result;
    }

}
